// miniprogram/pages/my/my.js
var app = getApp();
const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    winHeight: app.systeninfo.windowHeight,
    winWidth: app.systeninfo.windowWidth,
    userSetpInfo: {},
    vip: ''
  },
  goto() {
    wx.navigateTo({
      url: '../../userPublic/pages/openingVip/index',
    });
  },
  dk() {
    let that = this
    wx.request({
      url: app.APIURL + 'AddIntegrals',
      type: 'get',
      data: {
        type: 1,
        openId: app.openId,
      },
      success: function(res) {
        console.log(res)
        util.showError(res.data.msg)
        if (res.data.data){
          that.setData({
            userInfo: res.data.data[0]
          })
        }

      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    wx.cloud.init()
    wx.cloud.callFunction({
      name: 'getUserInfo',
    }).then(
      res => {
        console.log(res)
        // this.setData({
        //   openid: res.result.openId
        // })
        wx.request({
          url: app.APIURL + 'getUserInfo',
          type: 'get',
          data: {
            openId: res.result.openId
          },
          success: function(res) {
            console.log(res)
            that.setData({
              userInfo: res.data[0]
            })
          }
        })
        wx.request({
          url: app.APIURL + 'getUserSetpInfo',
          type: 'get',
          data: {
            openId: res.result.openId
          },
          success: function(res) {
            console.log(res)
            if (res.data.data.allDay < 30) {
              that.setData({
                vip: '初级跑者'
              })
            } else {
              that.setData({
                vip: '高级跑着'
              })
            }
            that.setData({
              userSetpInfo: res.data.data
            })
          }
        })
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})